package com.example.demo.util;

import com.example.demo.domain.Category;

import java.util.ArrayList;
import java.util.List;

public class FormatterCategory {
    private List<Category> arr;

    public FormatterCategory(List<Category> categoryList) {
        this.arr = categoryList;
    }

    public List<Category> findCategory(Long parent){
        List<Category> resCategory = new ArrayList<>();
        for(Category cat : this.arr){
            if(cat.getParent().equals(parent)){
                resCategory.add(cat);
                cat.setChildren(this.findCategory(cat.getId()));
            }
        }
        return resCategory;
    }

    public String formattrCategoryName(Long id){
        String name = "";
        for(Category cat : this.arr){
            if(cat.getId().equals(id)){
                name=cat.getName();
            }
        }
        return name;
    }
}
